import 'dart:async';

import 'package:flutter/material.dart';
import 'package:pixelyear/Routes.dart';
import 'package:pixelyear/sql/Sql.dart';
import 'package:pixelyear/utils/FunctionUtils.dart';
import 'package:pixelyear/utils/constant/AssetsConstant.dart';
import 'package:pixelyear/utils/ImageLoad.dart';
import 'package:pixelyear/widget/StateBarLessWidget.dart';

class SplashUI extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SplashState();
  }
}

class SplashState extends State<SplashUI> {
  @override
  void initState() {
    super.initState();
    init();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: StateBarLessWidget(
            child: ImageLoad.loadAssets(AssetsConstant.splash,
                width: double.infinity,
                height: double.infinity,
                fit: BoxFit.fill,
                tap: () {})),
        onWillPop: () async {
          return false;
        });
  }

  init() async {
    var colorUtils = Sql.getColorUtils();
    await colorUtils.addDefault();
    FunctionUtils.saveFirstJoinTime();
    Timer.periodic(Duration(milliseconds: 2000), (timer) {
      Navigator.pushNamedAndRemoveUntil(
          context, RoutesString.home, (route) => false);
      timer.cancel();
    });
  }
}
